<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SQL
 *
 * @author hodek
 */
class SQL {
    
    public static $select_user = "SELECT * FROM `user` WHERE `login` = '%s' AND `pass` = '%s'";
    public static $insert_user = "INSERT INTO user (login,pass,wrongLoginCount,email,role) VALUES ('%s','%s',0,'%s','%s')";    
    public static $update_userSessionId = "UPDATE user SET sessionId = '%s' WHERE id = %s";
    public static $select_userSessionId = "SELECT sessionId FROM user WHERE id = %s";

    public static $select_text_byName = "SELECT * FROM text WHERE name = '%s' AND preview = 0";    
    public static $select_textHistory_byName = "SELECT a . * , b.login FROM textHistory a INNER JOIN user b ON a.editedBy = b.id WHERE name = '%s' ORDER BY `date` DESC";
    public static $select_textHistory_byId = "SELECT * FROM textHistory WHERE id = '%s'";
    public static $select_text_byName_preview = "SELECT * FROM text WHERE name = '%s' AND preview = 1";
    public static $insert_textcz = "INSERT INTO textcz (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', %s,CURRENT_TIMESTAMP,0); ";
    public static $insert_textru = "INSERT INTO textru (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', %s,CURRENT_TIMESTAMP,0); ";
    public static $insert_texten = "INSERT INTO texten (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', %s,CURRENT_TIMESTAMP,0); ";
    public static $insert_text_preview = "INSERT INTO text (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', '%s',CURRENT_TIMESTAMP,1); ";
    /*public static $insert_textHistory = "INSERT INTO `textHistory` (`id` ,`name` ,`data` ,`editedBy` ,`date`)
VALUES (NULL ,'%s', '%s', '%s',CURRENT_TIMESTAMP); ";*/
    public static $update_text_byName_current = "UPDATE text SET data = '%s',editedBy = '%s' WHERE text.name = '%s' AND preview = 0";
    public static $update_text_byName_preview = "UPDATE text SET `data` = '%s',`editedBy` = '%s' WHERE text.`name` = '%s' AND preview = 1";

    public static $select_int_byName = "SELECT * FROM number WHERE name = '%s' AND preview = 0";
    public static $select_intHistory_byName = "SELECT a . * , b.login FROM numberHistory a INNER JOIN user b ON a.editedBy = b.id WHERE name = '%s' ORDER BY `date` DESC";
    public static $select_intHistory_byId = "SELECT * FROM numberHistory WHERE id = '%s'";
    public static $select_int_byName_preview = "SELECT * FROM number WHERE name = '%s' AND preview = 1";
    public static $insert_int = "INSERT INTO `number` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', '%s',CURRENT_TIMESTAMP,0); ";
    public static $insert_int_preview = "INSERT INTO `number` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', '%s',CURRENT_TIMESTAMP,1); ";
    public static $insert_int_empty = "INSERT INTO `number` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', null, '%s',CURRENT_TIMESTAMP,0); ";
    public static $insert_int_preview_empty = "INSERT INTO `number` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', null, '%s',CURRENT_TIMESTAMP,1); ";
    public static $insert_intHistory = "INSERT INTO `numberHistory` (`id` ,`name` ,`data` ,`editedBy` ,`date`)
VALUES (NULL ,'%s', '%s', '%s',CURRENT_TIMESTAMP); ";
    public static $update_int_byName_current = "UPDATE `number` SET `data` = '%s',`editedBy` = '%s' WHERE `number`.`name` = '%s' AND preview = 0";
    public static $update_int_byName_preview = "UPDATE `number` SET `data` = '%s',`editedBy` = '%s' WHERE `number`.`name` = '%s' AND preview = 1";

    public static $select_date_byName = "SELECT * FROM date WHERE name = '%s' AND preview = 0";
    public static $select_dateHistory_byName = "SELECT a . * , b.login FROM dateHistory a INNER JOIN user b ON a.editedBy = b.id WHERE name = '%s' ORDER BY `date` DESC";
    public static $select_dateHistory_byId = "SELECT * FROM dateHistory WHERE id = '%s'";
    public static $select_date_byName_preview = "SELECT * FROM date WHERE name = '%s' AND preview = 1";
    public static $insert_date = "INSERT INTO `date` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', '%s',CURRENT_TIMESTAMP,0); ";
    public static $insert_date_empty = "INSERT INTO `date` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', null, '%s',CURRENT_TIMESTAMP,0); ";
    public static $insert_date_preview = "INSERT INTO `date` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', '%s', '%s',CURRENT_TIMESTAMP,1); ";
    public static $insert_date_preview_empty = "INSERT INTO `date` (`name` ,`data` ,`editedBy` ,`date`,`preview`)
VALUES ('%s', null, '%s',CURRENT_TIMESTAMP,1); ";
    public static $insert_dateHistory = "INSERT INTO `dateHistory` (`id` ,`name` ,`data` ,`editedBy` ,`date`)
VALUES (NULL ,'%s', '%s', '%s',CURRENT_TIMESTAMP); ";
    public static $update_date_byName_current = "UPDATE `date` SET `data` = '%s',`editedBy` = '%s' WHERE `date`.`name` = '%s' AND preview = 0";
    public static $update_date_byName_preview = "UPDATE `date` SET `data` = '%s',`editedBy` = '%s' WHERE `date`.`name` = '%s' AND preview = 1";

    public static $select_itemType_byName_current = "SELECT a.id, b.data, a.value FROM itemtype a INNER JOIN text b ON a.value = b.name WHERE a.name = '%s' AND b.preview = 0";
    public static $select_itemType_byName_preview = "SELECT a.id, b.data, a.value FROM itemtype a INNER JOIN text b ON a.value = b.name WHERE a.name = '%s' AND b.preview = 1";
    public static $select_itemMap_byItemNameType_textSort = "SELECT DISTINCT a.itemId FROM itemmap a INNER JOIN text c ON a.valueId = c.name WHERE a.typeId = '%s' AND a.name = '%s' AND c.preview = 0 ORDER BY c.data %s LIMIT 0 , %s";
    public static $select_itemMap_byItemNameType_textSort_preview = "SELECT DISTINCT a.itemId FROM itemmap a INNER JOIN text c ON a.valueId = c.name WHERE a.typeId = '%s' AND a.name = '%s' AND c.preview = 1 ORDER BY c.data %s LIMIT 0 , %s";
    public static $select_itemMap_byItemNameType_numberSort = "SELECT DISTINCT a.itemId FROM itemmap a INNER JOIN number c ON a.valueId = c.name WHERE a.typeId = '%s' AND a.name = '%s' AND c.preview = 0 ORDER BY c.data %s LIMIT 0 , %s";
    public static $select_itemMap_byItemNameType_numberSort_preview = "SELECT DISTINCT a.itemId FROM itemmap a INNER JOIN number c ON a.valueId = c.name WHERE a.typeId = '%s' AND a.name = '%s' AND c.preview = 1 ORDER BY c.data %s LIMIT 0 , %s";
    public static $select_itemMap_byItemNameType_dateSort = "SELECT DISTINCT a.itemId FROM itemmap a INNER JOIN date c ON a.valueId = c.name WHERE a.typeId = '%s' AND a.name = '%s' AND c.preview = 0 ORDER BY c.data %s LIMIT 0 , %s";
    public static $select_itemMap_byItemNameType_dateSort_preview = "SELECT DISTINCT a.itemId FROM itemmap a INNER JOIN date c ON a.valueId = c.name WHERE a.typeId = '%s' AND a.name = '%s' AND c.preview = 1 ORDER BY c.data %s LIMIT 0 , %s";
    public static $select_itemMap_byNameType = "SELECT DISTINCT a.valueType, a.typeId, a.name FROM itemmap a INNER JOIN itemtype b ON a.typeID = b.id WHERE a.name = '%s' AND b.name = '%s' LIMIT 0 , 1";    
    public static $select_itemId = "SELECT valueId, valueType FROM itemmap WHERE itemId = %s AND name = '%s' AND typeId = %s";
    public static $insert_itemType_empty = "INSERT INTO `itemtype` (`id` ,`name` ,`value`)
VALUES ( NULL , '%s', '%s');";
    public static $insert_item_empty = "INSERT INTO `itemmap` (`name` ,`typeId` ,`valueId` ,`valueType` ,`itemId`)
VALUES ('%s', '%s', '%s', '%s', '%s');";
    public static $select_itemMap_byType = "SELECT DISTINCT a.name, a.valueType,a.typeId, b.id FROM itemmap a INNER JOIN itemtype b ON a.typeId = b.id WHERE b.name = '%s'";
    public static $select_itemMap_byTypeIdAndItemId = "SELECT * FROM itemmap WHERE typeId = %s AND itemId = %s";
    
    public static $insert_genId = "INSERT INTO `genid` (`id`)VALUES (NULL);";
    public static $insert_sqlDebug = "INSERT INTO `sqldebug` (`id` ,`query` ,`time` ,`post`, `session`)VALUES (NULL , '%s',CURRENT_TIMESTAMP , NULL, NULL);";
    
    //public static $delete_itemFromMap_byItemTypeId_text = "DELETE itemmap , text FROM itemmap , text WHERE itemmap.itemId = %s AND itemmap.typeId = %s AND  itemmap.valueId = text.name;";
    public static $delete_itemFromMap_byItemTypeId_date = "DELETE itemmap , date FROM itemmap , date WHERE itemmap.itemId = %s AND itemmap.typeId = %s AND  itemmap.valueId = date.name;";
    public static $delete_itemFromMap_byItemTypeId_int = "DELETE itemmap , number FROM itemmap , number WHERE itemmap.itemId = %s AND itemmap.typeId = %s AND  itemmap.valueId = number.name;";
    public static $delete_itemFromMap_byItemId = "DELETE itemmap, img, number, textcz, textru, texten, date, dyncismap, dynstruc FROM itemmap LEFT JOIN img ON (itemmap.valueid = img.name) LEFT JOIN textcz ON (itemmap.valueid = textcz.name) LEFT JOIN texten ON (itemmap.valueid = texten.name) LEFT JOIN textru ON (itemmap.valueid = textru.name) LEFT JOIN number ON (itemmap.valueid = number.name) LEFT JOIN date ON (itemmap.valueid = date.name) LEFT JOIN dynstruc ON (itemmap.valueid = dynstruc.name) LEFT JOIN dyncismap ON (dyncismap.id = dynstruc.idcismap) LEFT JOIN img img2 ON (img2.name = dyncismap.fkname) WHERE itemmap.itemid = %s";    
    public static $delete_tree ="DELETE itemtype, a, b FROM itemtype LEFT JOIN subtypemapping a ON (a.parent = itemtype.id) LEFT JOIN subtypemapping b ON (b.child = itemtype.id) WHERE itemtype.id = %s";
    
//SELECT * FROM itemmap LEFT JOIN img ON (itemmap.valueid = img.name) LEFT JOIN text ON (itemmap.valueid = text.name) LEFT JOIN number ON (itemmap.valueid = number.name) LEFT JOIN date ON (itemmap.valueid = date.name) LEFT JOIN dynstruc ON (itemmap.valueid = dynstruc.name) LEFT JOIN dyncismap ON (dyncismap.id = dynstruc.idcismap) LEFT JOIN img img2 ON (img2.name = dyncismap.fkname) WHERE itemmap.itemid = 229

    public static function getYearFromDBDateTime($dateTime) {
        $myArray = explode("-",$dateTime);
        return $myArray[0];
    }

    public static function getMonthFromDBDateTime($dateTime) {
        $myArray = explode("-",$dateTime);
        if (isset($myArray[1])){
            return (int)$myArray[1];
        }else{
            return 0;
        }
        
    }

    public static function getDayFromDBDateTime($dateTime) {
        $myArray = explode(" ",$dateTime);
        $myArray = explode("-",$dateTime);
        if (isset($myArray[2])){
            return (int)$myArray[2];
        }else{
            return 0;
        }        
    }
    
    public static $select_itemType_byName = "SELECT id, name, value FROM itemtype WHERE name LIKE '%s'";
    
    public static $select_itemType_byId_current = "SELECT a.id, b.data, a.value FROM itemtype a INNER JOIN text b ON a.value = b.name WHERE a.id = %s AND b.preview = 0";
    public static $select_subtypeMapping_byParent = "SELECT parent, child FROM subtypemapping WHERE parent = %s ORDER BY sortNumber";
    public static $select_subtypeMapping = "SELECT a.parent, a.child, b.name, b.id, c.data FROM subtypemapping a LEFT JOIN itemtype b ON b.id = a.child LEFT JOIN text c ON b.value =  c.name";    
    public static $insert_subtypeMapping = "INSERT INTO `subtypemapping` (`parent` ,`child`) VALUES (%s , %s);";
    
    public static $select_itemType_allExceptMain = "SELECT a.id, a.name, b.data FROM itemtype a INNER JOIN text b ON a.value = b.name WHERE b.preview = 0 ORDER BY b.data";
    
    public static $select_ciselnik_barvy = "SELECT value,idval FROM ciselnik WHERE id = 1";
    public static $select_ciselnik_barvy_byIdVal = "SELECT value FROM ciselnik WHERE id = 1 AND idval = %s";
    public static $select_ciselnik_velikosti = "SELECT value,idval, sortNumber FROM ciselnik WHERE id = 2 ORDER BY sortNumber";
    public static $select_ciselnik_velikosti_byIdVal = "SELECT value, sortNumber FROM ciselnik WHERE id = 2 AND idval = %s ORDER BY sortNumber";
    public static $select_ciselnik_byValue = "SELECT idval FROM ciselnik WHERE value = '%s'";
    
    public static $insert_img = "INSERT INTO `img` (`name` ,`editedBy` ,`date`,`preview`, `fullSize`, `mediumSize`, `smallSize`, ext)
VALUES ('%s', '%s', CURRENT_TIMESTAMP,0, '%s', '%s', '%s', '%s'); ";
    public static $insert_adresa = "INSERT INTO adresa VALUES (%s, '%s', '%s', %s, '%s', '%s', '%s', %s, null, '%s', '%s', '%s')";
    public static $update_adresa= "UPDATE adresa SET ulice = '%s', mesto = '%s', psc = %s, stat = %s, mobil = %s, firma = '%s', ic = %s,  jmeno = '%s', prijmeni = '%s'  WHERE userId = %s AND stav = '%s'";
    public static $insert_img_preview = "INSERT INTO `img` (`name` ,`editedBy` ,`date`,`preview`, `fullSize`, `mediumSize`, `smallSize`, ext)
VALUES ('%s', '%s', CURRENT_TIMESTAMP,1, '%s', '%s', '%s','%s'); ";
    
    public static $insert_dyn = "INSERT INTO `dynstruc` (`name` ,`editedBy` ,`date`,`preview`, `idcismap`)
VALUES ('%s', '%s', CURRENT_TIMESTAMP,0, '%s'); ";
    public static $insert_dyn_preview = "INSERT INTO `dynstruc` (`name` ,`editedBy` ,`date`,`preview`, `idcismap`)
VALUES ('%s', '%s', CURRENT_TIMESTAMP,1, '%s'); ";
    
    public static $insert_dyncismap = "INSERT INTO `dyncismap` (`id` ,`idcis` ,`idval`)
VALUES ('%s', '%s', '%s');";
    public static $insert_dyncismap_full = "INSERT INTO `dyncismap` (`id` ,`idcis` ,`idval`, `fkname`)
VALUES ('%s', '%s', '%s','%s');";    
    
    public static $select_ciselnik_byid = "SELECT value, idval FROM ciselnik WHERE id = %s";
    
    public static $insert_ciselnik = "INSERT INTO ciselnik (id,value,sortNumber) VALUES (%s,'%s',%s);";
    
    public static $select_itemBy_idAndName = "SELECT b.data textData, a.itemId, e.name, f.idcismap,c.data numberData,d.data dateData, a.valueId
        FROM itemmap a 
        LEFT JOIN text b ON (a.valueid = b.name) 
        LEFT JOIN number c ON (a.valueid = c.name) 
        LEFT JOIN date d ON (a.valueid = d.name) 
        LEFT JOIN img e ON (a.valueid = e.name) 
        LEFT JOIN dynstruc f ON (a.valueid = f.name) WHERE a.name = '%s' AND a.itemid = %s AND( b.preview = 0 OR c.preview = 0 OR e.preview = 0 OR d.preview = 0 OR f.preview = 0)";    
    public static $select_dyncismap_byIdCisMap = "SELECT idcis, b.idval, fkname, value FROM dyncismap a LEFT JOIN ciselnik b ON (a.idval = b.idval)WHERE a.id = %s";
    public static $select_dyncismap_byIdCisMapAndIdVal = "SELECT fkname FROM dyncismap a JOIN img b ON (a.fkname = b.name) WHERE a.id = %s AND a.idval = %s";
    public static $delete_dyncismap_byIdCisMap = "DELETE dyncismap FROM dyncismap WHERE id = %s;";
    public static $delete_dyncismap_byIdCisMapAndIdVal = "DELETE dyncismap, img FROM dyncismap LEFT JOIN img ON (dyncismap.fkname = img.name) WHERE id = %s AND idval = %s";
    
    public static $select_items_byTypeId = "SELECT DISTINCT a.itemId,a.typeId FROM itemmap a LEFT JOIN number b ON (a.valueid = b.name) WHERE (";
    
    public static $select_img_byName_full = "SELECT fullSize,ext FROM img WHERE name LIKE '%s'";
    public static $select_img_byName_medium = "SELECT mediumSize,ext FROM img WHERE name LIKE '%s'";
    public static $update_img_byName = "UPDATE img SET date = CURRENT_TIMESTAMP  WHERE name LIKE '%s'";
    public static $select_img_byName_small = "SELECT smallSize,ext FROM img WHERE name LIKE '%s'";
    public static $select_img_byItemIdAndBarvaIdVal = "SELECT a.idlink FROM recurrentid a WHERE a.idmain= '%s' ";
    public static $select_text_byImteIdAndName = "SELECT b.data FROM itemmap a JOIN text b ON (a.valueid = b.name) WHERE a.itemId = %s AND a.name = '%s' AND b.preview = '0'";
    public static $select_int_byImteIdAndName = "SELECT b.data FROM itemmap a JOIN number b ON (a.valueid = b.name) WHERE a.itemId = %s AND a.name = '%s' AND b.preview = '0'";
    public static $searchItems = "SELECT DISTINCT a.itemId, a.typeId FROM itemmap a JOIN text b ON (a.valueId = b.name) WHERE (a.name = 'popis' OR a.name = 'nadpis') AND (";
    public static $searchItemsBySize = "SELECT DISTINCT a.itemId, a.typeId, d.value FROM itemmap a JOIN dynstruc b ON (a.valueId = b.name) JOIN dyncismap c ON (b.idcismap = c.id) JOIN ciselnik d ON (d.idval = c.idval) WHERE a.name = 'velikosti' AND d.value LIKE '%s'";
    public static $searchMore = "INSTR(LCASE(b.data),LCASE('%s')) > 0";
    public static $select_sklad = "INSERT INTO dyncismap (id ,idcis ,idval, fkname) SELECT sub.idcismap AS id, %s AS idcis, idval as idval, '%s' as fkname FROM ciselnik, (SELECT idcismap FROM itemmap LEFT JOIN dynstruc ON (valueid = dynstruc.name) WHERE itemid = %s AND itemmap.name = 'sklad') AS sub WHERE INSTR(ciselnik.value,'%s') > 0";
    public static $copyImage = "INSERT INTO img (name, editedBy,date,preview, fullsize, mediumSize, smallSize, ext) SELECT '%s' as name, editedBy, date, preview, fullSize, mediumSize, smallSize, ext FROM img WHERE name = '%s'";
    public static $update_img = "UPDATE img SET editedBy = '%s', fullSize = '%s', mediumSize = '%s', smallSize = '%s', ext = '%s' WHERE name = '%s'";
    public static $update_section_byItemId = "UPDATE itemmap SET typeId = (SELECT id FROM itemtype WHERE name = '%s') WHERE itemid = %s";
    public static $update_sklad = "UPDATE dyncismap SET fkname = '%s' WHERE id = %s AND idval = (SELECT idval FROM ciselnik WHERE value = '%s')";
    public static $checkSklad = "SELECT ciselnik.value, ciselnik.idval, dyncismap.id, dyncismap.idcis FROM itemmap LEFT JOIN dynstruc ON (dynstruc.name = itemmap.valueid) LEFT JOIN dyncismap ON (dynstruc.idcismap = dyncismap.id) LEFT JOIN ciselnik ON (ciselnik.idval = dyncismap.idval)WHERE (itemmap.name = 'sklad' OR itemmap.name = 'velikosti' OR itemmap.name = 'barvy') AND itemmap.itemid = %s ";
    public static $select_dyncismap_byItemId = "SELECT dynstruc.idcismap FROM itemmap LEFT JOIN dynstruc ON (itemmap.valueid = dynstruc.name) WHERE itemid = %s AND itemmap.name = '%s'";
    public static $update_sectionParent = "UPDATE subtypemapping SET parent = %s WHERE child = %s";
    public static $delete_dyncismap_byfkname = "DELETE dyncismap, img FROM dyncismap LEFT JOIN img ON (dyncismap.fkname = img.name) WHERE fkname = '%s'";
    public static $insert_recurrentId = "INSERT INTO recurrentid (idmain, idlink) VALUES ('%s','%s')";
    public static $select_recurrentLinkId = "SELECT * FROM recurrentid WHERE idmain = '%s'";
    public static $delete_colour = "DELETE dyncismap, recurrentid, texten, textcz, textru, img FROM dyncismap LEFT JOIN texten ON (texten.name = dyncismap.fkname) LEFT JOIN textru ON (textru.name = dyncismap.fkname) LEFT JOIN textcz ON (textcz.name = dyncismap.fkname) LEFT JOIN recurrentid ON (recurrentid.idmain = dyncismap.fkname) LEFT JOIN img ON (img.name = recurrentid.idlink) WHERE fkname = '%s'";    
    public static $delete_img = "DELETE img FROM img WHERE name = '%s'";
    public static $delete_recurrent = "DELETE recurrentid FROM recurrentid WHERE idlink = '%s'";
    public static $select_skladDynCisMapId = "SELECT d.idcismap FROM dynstruc a LEFT JOIN itemmap b ON (a.name = b.valueid) LEFT JOIN itemmap c ON (c.itemid = b.itemid) LEFT JOIN dynstruc d ON (d.name = c.valueid) WHERE a.idcismap = %s AND c.name = 'sklad'";
    public static $delete_sklad = "DELETE dyncismap, recurrentid, number FROM dyncismap LEFT JOIN number ON (number.name = dyncismap.fkname) LEFT JOIN recurrentid ON (recurrentid.idmain = dyncismap.fkname) WHERE dyncismap.fkname = '%s'";
    
    public static $select_orders = "SELECT * FROM orders WHERE stav = %s";
    public static $insert_orders = "INSERT INTO orders (cisloObjednavky, itemId, znacka, velikost, mnozstvi, uzivatel, stav, odber) VALUES (null, %s, %s, %s, %s, %s, %s, %s)";
    public static $update_order  = "UPDATE orders SET stav = %s WHERE cisloObjednavky = %s";
    
    public static $select_adresa_userId = "SELECT * FROM adresa WHERE userId = %s";
    
    public static $insert_order = "INSERT INTO orders VALUES (null, %s, %s, '%s', '%s', null)";
    public static $insert_orderitems = "INSERT INTO orderitems VALUES (null, %s, %s, '%s', %s, %s, %s, '%s')";
    
    public static $select_ordersAdmin = "SELECT orderitemsid, a.orderid, a.odber, uzivatel, cenacelk, a.stav, b.stav as itemstav, odber, cas, g.data as item_name,h.data as znacka,e.value as velikost,mnozstvi, cena, login, ulice, mesto, psc, stat, mobil, firma, ic, d.stav AS adresaStav, jmeno, prijmeni  FROM orders a INNER JOIN orderitems b ON a.orderid = b.orderid INNER JOIN user c ON c.id = a.uzivatel INNER JOIN adresa d ON d.userid = c.id INNER JOIN ciselnik e ON e.idval = velikost INNER JOIN itemmap f ON f.itemid = b.itemid INNER JOIN textcz g ON g.name = f.valueid INNER JOIN textcz h ON h.name = znacka  WHERE a.stav !=  '%s' AND f.name = 'nadpis' ORDER BY cas DESC";
    public static $select_ordersAdminById = "SELECT orderitemsid, a.orderid, a.odber, uzivatel, cenacelk, a.stav, b.stav as itemstav, odber, cas, g.data as item_name,h.data as znacka,e.value as velikost,mnozstvi, cena, login, ulice, mesto, psc, stat, mobil, firma, ic, d.stav AS adresaStav, jmeno, prijmeni  FROM orders a INNER JOIN orderitems b ON a.orderid = b.orderid INNER JOIN user c ON c.id = a.uzivatel INNER JOIN adresa d ON d.userid = c.id INNER JOIN ciselnik e ON e.idval = velikost INNER JOIN itemmap f ON f.itemid = b.itemid INNER JOIN textcz g ON g.name = f.valueid INNER JOIN textcz h ON h.name = znacka  WHERE a.stav !=  '%s' AND f.name = 'nadpis' AND a.orderid = %s ORDER BY cas DESC";
    public static $select_ordersUser = "SELECT orderitemsid, a.orderid, a.odber, uzivatel, cenacelk, a.stav, b.stav as itemstav, odber, cas, g.data as item_name,h.data as znacka,e.value as velikost,mnozstvi, cena, login, ulice, mesto, psc, stat, mobil, firma, ic, d.stav AS adresaStav, jmeno, prijmeni  FROM orders a INNER JOIN orderitems b ON a.orderid = b.orderid INNER JOIN user c ON c.id = a.uzivatel INNER JOIN adresa d ON d.userid = c.id INNER JOIN ciselnik e ON e.idval = velikost INNER JOIN itemmap f ON f.itemid = b.itemid INNER JOIN textcz g ON g.name = f.valueid INNER JOIN textcz h ON h.name = znacka  WHERE a.stav !=  '%s' AND f.name = 'nadpis' AND a.uzivatel = '%s' ORDER BY cas DESC";
    public static $select_ordersUserById = "SELECT orderitemsid, a.orderid, a.odber, uzivatel, cenacelk, a.stav, b.stav as itemstav, odber, cas, g.data as item_name,h.data as znacka,e.value as velikost,mnozstvi, cena, login, ulice, mesto, psc, stat, mobil, firma, ic, d.stav AS adresaStav, jmeno, prijmeni  FROM orders a INNER JOIN orderitems b ON a.orderid = b.orderid INNER JOIN user c ON c.id = a.uzivatel INNER JOIN adresa d ON d.userid = c.id INNER JOIN ciselnik e ON e.idval = velikost INNER JOIN itemmap f ON f.itemid = b.itemid INNER JOIN textcz g ON g.name = f.valueid INNER JOIN textcz h ON h.name = znacka  WHERE a.stav !=  '%s' AND f.name = 'nadpis' AND a.orderid = %s AND a.uzivatel = '%s' ORDER BY cas DESC";
    public static $update_orderStav = "UPDATE orders SET stav = '%s' WHERE orderId = %s";
    





    public function __construct() {
        $text = "text".$GLOBALS["lang"]["ac"];
        SQL::$select_text_byName = str_replace("text", $text, SQL::$select_text_byName);
        SQL::$select_text_byName_preview = str_replace("text", $text, SQL::$select_text_byName_preview);
        //SQL::$insert_text = str_replace("text", $text, SQL::$insert_text);
        //SQL::$insert_text_preview = str_replace("text", $text, SQL::$insert_text_preview);
        SQL::$update_text_byName_current = str_replace("text", $text, SQL::$update_text_byName_current);
        SQL::$update_text_byName_preview = str_replace("text", $text, SQL::$update_text_byName_preview);
        SQL::$select_itemType_byName_current = str_replace("text", $text, SQL::$select_itemType_byName_current);
        SQL::$select_subtypeMapping = str_replace("text", $text, SQL::$select_subtypeMapping);
        SQL::$select_itemType_byName_preview = str_replace("text", $text, SQL::$select_itemType_byName_preview);
        SQL::$select_itemMap_byItemNameType_textSort = str_replace("text", $text, SQL::$select_itemMap_byItemNameType_textSort);
        SQL::$select_itemMap_byItemNameType_textSort_preview = str_replace("text", $text, SQL::$select_itemMap_byItemNameType_textSort_preview);
        //SQL::$delete_itemFromMap_byItemTypeId_text = str_replace("text", $text, SQL::$delete_itemFromMap_byItemTypeId_text);
        //SQL::$delete_itemFromMap_byItemId = str_replace("text", $text, SQL::$delete_itemFromMap_byItemId);
        SQL::$select_text_byImteIdAndName = str_replace("text", $text, SQL::$select_text_byImteIdAndName);
        SQL::$searchItems = str_replace("text", $text, SQL::$searchItems);
        SQL::$select_itemBy_idAndName = str_replace(" text ", " ".$text." ", SQL::$select_itemBy_idAndName);
        SQL::$select_itemType_byId_current = str_replace("text", $text, SQL::$select_itemType_byId_current);
        SQL::$select_itemType_allExceptMain = str_replace("text", $text, SQL::$select_itemType_allExceptMain);
    }
}
?>
